home *** CD-ROM | disk | FTP | other *** search
- Path: news.rmii.com!usenet
- From: jcoffin@rmii.com (Jerry Coffin)
- Newsgroups: comp.std.c
- Subject: Re: static and extern, and a variable be both ?
- Date: Thu, 04 Jan 1996 17:33:43 GMT
- Organization: TAEUS
- Message-ID: <4cgv6u$ogu@natasha.rmii.com>
- References: <ahicksDKMG56.K20@netcom.com>
- NNTP-Posting-Host: slip8152.rmii.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- ahicks@netcom.com (Aaron Hicks at Netcom) wrote:
-
- > After much looking and little finding I have come to ask for your
- >assistance. I'm working on a project in which we believed the best way
- >to insure a 500K array was allocated corectly was to declare it as static
- >and then when we needed to use it in a nother program to declare it there as
- >an extern. When we did this we got a variable undefined error during the
- >linking of the programs. Now my question is this a standard C compiler
- >thing or is this compiler wrong. Below are the relative parts of the code:
-
- [ ... ]
-
- >I have found that this will work if I just do not declare the array as
- >a static in the first place. It then will work fine, but we a slightly
- >afraid that if we do not declare this as static when it is declared there
- >may not be enough memory left after the other parts of this program have
- >ran of a while.
-
- As long as the varaible is declared at file scope (i.e. outside any
- function), it'll have static storage duration (which seems to be what
- you want.) If you use `static' explicitly, it will give the identifier
- internal linkage, which means it will only be visible within that
- translation unit. (i.e. that source module)
-
- In short, it sounds like leaving the `static' off is exactly what you
- need, and shouldn't cause a problem.
- Later,
- Jerry.
-
- /* I can barely express my own opinions; I certainly can't
- * express anybody else's.
- *
- * The universe is a figment of its own imagination.
- */
-
-